var Light = (function () {
    var weakLight=function (light) {
        this.light=light;
    },offLight=function (light) {
        this.light=light;
    },heightLight=function (light) {
        this.light=light;
    },LightFun=function () {
        this.offState=new offLight(this);
        this.weakState=new weakLight(this);
        this.heightState=new heightLight(this);
        this.button=null;
    };
    weakLight.prototype.buttonWasPressed=function () {
        alert('强光');
        this.light.setState(this.light.heightState);
    };
    offLight.prototype.buttonWasPressed=function(){
        alert('弱光');
        this.light.setState(this.light.weakState);
    };
    heightLight.prototype.buttonWasPressed=function(){
        alert('关闭');
        this.light.setState(this.light.offState);
    };
    LightFun.prototype.init=function(){
        var self=this,
            button=document.createElement('button');
        this.currState=this.offState;
        button.innerHTML='开关';
        this.button=document.body.appendChild(button);
        this.button.addEventListener('click',function () {
            self.currState.buttonWasPressed();
        })
    };
    LightFun.prototype.setState=function (newState) {
        this.currState=newState;
    };
    return LightFun;
})();
$(function () {
    new Light().init();
});